<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>

<head>
    <title>Test Page - Amazon Web Services (AWS)</title>

	<link href="http://www.mattsnider.com//assets/css/library.css" type="text/css" rel="stylesheet"/>
	<link href="/assets/css/test.css" type="text/css" rel="stylesheet"/>

	<style type="text/css">
	#form-aws .BrowseNodeLookup,
	#form-aws .CartAdd,
	#form-aws .CartCreate,
	#form-aws .CartModify,
	#form-aws .CartGet,
	#form-aws .CartClear,
	#form-aws .CustomerContentLookup,
	#form-aws .CustomerContentSearch,
	#form-aws .ItemLookup,
	#form-aws .ItemSearch,
	#form-aws .ListLookup,
	#form-aws .ListSearch,
	#form-aws .SimilarityLookup {
		display: none;
	}
	
	#form-aws.BrowseNodeLookup .BrowseNodeLookup,
	#form-aws.CartAdd .CartAdd,
	#form-aws.CartCreate .CartCreate,
	#form-aws.CartModify .CartModify,
	#form-aws.CartGet .CartGet,
	#form-aws.CartClear .CartClear,
	#form-aws.CustomerContentLookup .CustomerContentLookup,
	#form-aws.CustomerContentSearch .CustomerContentSearch,
	#form-aws.ItemLookup .ItemLookup,
	#form-aws.ItemSearch .ItemSearch,
	#form-aws.ListLookup .ListLookup,
	#form-aws.ListSearch .ListSearch,
	#form-aws.SimilarityLookup .SimilarityLookup {
		display: block;
	}
    </style>
</head>

<body id="project"><div id="doc">

	<h1>Test Page - Amazon Web Services (AWS)</h1>

	<p>The AWS Utility allows you to make queries against the Amazon Web Services API. For the simplest usage,
	enter any UPC code and click submit. You will see the XML appear in the text field below and some basic
	information about the item.</p>

	<p>If you would like to see that result parsed as JSON, then change the responseType. Changing the ResponseGroup
	alters the content that is returned by Amazon. Almost every ResponseGroup is support by the XML system,
	but only about 1/3 are supported by the JSON parser (mostly because of parser limitations). The Operation is
	the what you would like AWS to do, if you use ItemLookup or SimilarityLookup then the UPC field will expect
	a UPC code. If you use ItemSearch, then the UPC field is actually a keyword search.</p>

	<div id="content">
		<div class="ItemLookup" id="form-aws"><form action="#" method="post" title="the form 1 is submitted"><fieldset>
			<legend>AWS UPC Form</legend>
			<dl>
				<dt class="ItemLookup"><label for="form-aws-upc">UPC:</label></dt>
				<dt class="ListLookup"><label for="form-aws-upc">ListId:</label></dt>
				<dd class="ItemLookup ListLookup"><input id="form-aws-upc" type="text" tabindex="1" name="upc" class="txt"/></dd>
				<dt class="BrowseNodeLookup"><label for="form-aws-node">Node Id:</label></dt>
				<dd class="BrowseNodeLookup"><input id="form-aws-node" type="text" tabindex="1" name="node" class="txt"/></dd>
				<dt class="CustomerContentLookup"><label for="form-aws-customer">Customer Id:</label></dt>
				<dd class="CustomerContentLookup"><input id="form-aws-customer" type="text" tabindex="1" name="customerId" class="txt"/></dd>
				<dt class="ItemSearch CustomerContentSearch ListSearch"><label for="form-aws-keywords">Keywords:</label></dt>
				<dd class="ItemSearch CustomerContentSearch ListSearch"><input id="form-aws-keywords" type="text" tabindex="1" name="keywords" class="txt"/></dd>
				<dt><label for="form-aws-responseGroup">ResponseGroup:</label></dt>
				<dd><select id="form-aws-responseGroup" tabindex="2" name="responseGroup">
					<option value="Accessories">Accessories</option>
					<option value="AlternateVersions">AlternateVersions</option>
					<option value="BrowseNodeInfo">BrowseNodeInfo</option>
					<option value="BrowseNodes">BrowseNodes</option>
					<option class="disabled"disabled="disabled" value="Cart">Cart</option>
					<option class="disabled"disabled="disabled" value="CartNewReleases">CartNewReleases</option>
					<option value="Collections">Collections</option>
					<option value="CustomerFull">CustomerFull</option>
					<option value="CustomerInfo">CustomerInfo</option>
					<option value="CustomerLists">CustomerLists</option>
					<option value="CustomerReviews">CustomerReviews</option>
					<option value="EditorialReview">EditorialReview</option>
					<option value="Images">Images</option>
					<option value="ItemAttributes">ItemAttributes</option>
					<option value="ItemIds">ItemIds</option>
					<option value="ListFull">ListFull</option>
					<option value="ListInfo">ListInfo</option>
					<option value="ListItems">ListItems</option>
					<option value="ListmaniaLists">ListmaniaLists</option>
					<option value="ListMinimum">ListMinimum</option>
					<option value="Medium">Medium</option>
					<option value="MerchantItemAttributes">MerchantItemAttributes</option>
					<option value="NewReleases">NewReleases</option>
					<option value="Large">Large</option>
					<option value="OfferFull">OfferFull</option>
					<option value="OfferListings">OfferListings</option>
					<option value="Offers">Offers</option>
					<option value="OfferSummary">OfferSummary</option>
					<option value="PromotionDetails">PromotionDetails</option>
					<option value="PromotionSummary">PromotionSummary</option>
					<option value="PromotionalTag">PromotionalTag</option>
					<option value="RelatedItems">RelatedItems</option>
					<option value="Request">Request</option>
					<option value="Reviews">Reviews</option>
					<option value="SalesRank">SalesRank</option>
					<option value="SearchInside">SearchInside</option>
					<option value="ShippingCharges">ShippingCharges</option>
					<option value="Similarities">Similarities</option>
					<option value="Small" selected="selected">Small</option>
					<option value="Subjects">Subjects</option>
					<option value="Tags">Tags</option>
					<option value="TagsSummary">TagsSummary</option>
					<option value="Tracks">Tracks</option>
					<option value="Variations">Variations</option>
					<option value="VariationImages">VariationImages</option>
					<option value="VariationMatrix">VariationMatrix</option>
					<option value="VariationMinimum">VariationMinimum</option>
					<option value="VariationOffers">VariationOffers</option>
					<option value="VariationSummary">VariationSummary</option>
				</select></dd>
				<dt><label for="form-aws-responseType">ResponseType</label></dt>
				<dd><select id="form-aws-responseType" tabindex="3">
					<option value="json">json</option>
					<option value="xml" selected="selected">xml</option>
				</select></dd>
				<dt><label for="form-aws-operation">Operation</label></dt>
				<dd><select id="form-aws-operation" tabindex="4">
					<option value="BrowseNodeLookup">BrowseNodeLookup</option>
					<option class="disabled" disabled="disabled" value="CartAdd">CartAdd</option>
					<option class="disabled" disabled="disabled" value="CartClear">CartClear</option>
					<option class="disabled" disabled="disabled" value="CartCreate">CartCreate</option>
					<option class="disabled" disabled="disabled" value="CartGet">CartGet</option>
					<option class="disabled" disabled="disabled" value="CartModify">CartModify</option>
					<option value="CustomerContentLookup">CustomerContentLookup</option>
					<option value="CustomerContentSearch">CustomerContentSearch</option>
					<option value="ItemLookup" selected="selected">ItemLookup</option>
					<option value="ItemSearch">ItemSearch</option>
					<option value="ListLookup">ListLookup</option>
					<option value="ListSearch">ListSearch</option>
					<option value="SimilarityLookup">SimilarityLookup</option>
					<option class="disabled" disabled="disabled" value="TagLookup">TagLookup</option>
					<option class="disabled" disabled="disabled" value="TransactionLookup">TransactionLookup</option>
				</select></dd>
				<dt><label for="form-aws-other">Other Parameters</label></dt>
				<dd>
					<input id="form-aws-other" type="text" tabindex="5" name="other" class="txt"/><br/>
					<small>If you know what you are doing and have additional parameters (&key=value...).</small>
				</dd>
				<dd class="buttons">
					<input id="form-aws-submit" name="submit" tabindex="6" type="submit" value="submit"/>
				</dd>
			</dl>
		</fieldset></form></div>

		<div id="aws-results">
			<p><label>Title: </label><span id="aws-results-title"></span></p>
			<p><label>ASIN: </label><span id="aws-results-asin"></span></p>
			<p><label>Amazon URL: </label><span id="aws-results-url"></span></p>
			<p><label>AWS URL: </label><span id="aws-results-awsurl"></span></p>
		</div>

		<label for="form-aws-results">AWS Result</label>
		<textarea id="form-aws-results" rows="10" cols="60"></textarea>
	</div>

	<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui.js" type="text/javascript"></script>
	<script type="text/javascript">var r = '71';
	YUI({
		filter:'raw',
		combine: true,
		timeout: 10000,
		modules: {
			'gallery-aws': {
//				fullpath: 'http://yui-ext-mvc.googlecode.com/svn/trunk/assets/js/yahoo-3-ext/aws.js?r' + r,
				fullpath: 'http://core.localhost/assets/js/yahoo-3-ext/aws.js?r' + r,
				requires: ['base', 'io-base', 'io-xdr', 'json-parse', 'collection', 'datatype-xml'],
				optional: [],
				supersedes: []
			},
			'gallery-aws-json': {
//				fullpath: 'http://yui-ext-mvc.googlecode.com/svn/trunk/assets/js/yahoo-3-ext/aws-json.js?r' + r,
				fullpath: 'http://core.localhost/assets/js/yahoo-3-ext/aws-json.js?r' + r,
				requires: ['oop', 'datatype-json', 'dataschema-xml2', 'gallery-aws'],
				optional: [],
				supersedes: []
			},
			'dataschema-xml2': {
//				fullpath: 'http://yui-ext-mvc.googlecode.com/svn/trunk/assets/js/yahoo-3-ext/dataschema-xml2.js?r' + r,
				fullpath: 'http://core.localhost/assets/js/yahoo-3-ext/dataschema-xml2.js?r' + r,
				requires: ['dataschema-base'],
				optional: [],
				supersedes: []
			}
		}
	}).use('node', 'json-stringify', 'gallery-aws', 'gallery-aws-json', function(Y) {
		var _domCustomerId = Y.one('#form-aws-customer'),
			_domForm = Y.one('#form-aws'),
			_domNodeId = Y.one('#form-aws-node'),
			_domResults = Y.one('#form-aws-results'),
			_domResponseGroup = Y.one('#form-aws-responseGroup'),
			_domResponseType = Y.one('#form-aws-responseType'),
			_domOperation = Y.one('#form-aws-operation'),
			_domOther = Y.one('#form-aws-other'),
			_domResultTitle = Y.one('#aws-results-title'),
			_domResultAsin = Y.one('#aws-results-asin'),
			_domResultUrl = Y.one('#aws-results-url'),
			_domResultAWSUrl = Y.one('#aws-results-awsurl'),
			_domKeywords = Y.one('#form-aws-keywords'),
			_domUpc = Y.one('#form-aws-upc');

		function _getSelectedValue(node) {
			var selectedIndex = node.get('selectedIndex'),
				option;

			node.get('options').each(function(node) {
					if (node.get('index') === selectedIndex) {
						option = node;
					}
				});

			return option.get('value');
		}

		// hanlde the form submission
		Y.one('#form-aws form').on('submit', function(e) {
			e.halt();
			var aws = new Y.Aws({
				ioSWFURL: '/assets/files/io.swf',
				responseGroup: _getSelectedValue(_domResponseGroup),
				operation: _getSelectedValue(_domOperation),
				awsSignedUrl: '/getAWSSignedUrl.php?' + _domOther.get('value')
			}), data, value = _getSelectedValue(_domOperation);

			switch (value) {
				case 'BrowseNodeLookup':
					data = {BrowseNodeId:_domNodeId.get('value')};
				break;
			/*
				case 'CartAdd':
				case 'CartCreate':
				case 'CartModify':
				case 'CartGet':
				case 'CartClear':
					data = '';
					*/
				break;
				case 'CustomerContentLookup':
				case 'CustomerContentSearch':
					data = {CustomerId:_domCustomerId.get('value')};
				break;
				case 'ItemLookup':
				case 'SimilarityLookup':
					data = {ItemId:_domUpc.get('value'), IdType: 'ASIN'};
//					data = {ItemId:_domUpc.get('value'), IdType: 'UPC'};
				break;
				case 'ItemSearch':
				case 'ListSearch':
					data = {Keywords:_domKeywords.get('value')};
				break;
				case 'ListLookup':
					data = {ListId:_domUpc.get('value'), IdType: 'ListId'};
				break;
				default:
					alert('Operation "' + value + '" not yet supported');
					return;
			}
			
			aws.getJSON(data, function(id, o) {
				var isXML = 'xml' == _getSelectedValue(_domResponseType),
					json = o.responseJSON,
					result = json.results[0];

				_domResults.set('value', isXML ? Y.DataType.XML.format(o.responseXML) : Y.JSON.stringify(o.responseJSON, null, 4));
				_domResultAWSUrl.set('href', o.awsURL);
				_domResultAWSUrl.set('innerHTML', o.awsURL ? '<a href="' + o.awsURL + '">AWS URL</a>' : '');

				_domResultUrl.set('href', result ? result.detailPageURL : '');
				_domResultUrl.set('innerHTML', result && result.detailPageURL ? '<a href="' + result.detailPageURL + '">Amazon URL</a>' : '');
				_domResultTitle.set('innerHTML', result ? result.title : '');
				_domResultAsin.set('innerHTML', result ? result.asin : '');
			});
		});

		// update the form to handle operation
		_domOperation.on('change', function() {
			var value = _getSelectedValue(_domOperation);
			_domForm.set('className', value);
		});
	});</script>
</div></body>
</html>